var { getConnect } = require("../index")



function selectTable(column_name,table_name){
    var sql_str = ''
    if(column_name.length == 0){
        sql_str = `select * from ${table_name}`
    }else{
        let column_str = ''
        column_name.forEach((element,index,arr) => {
            column_str+element+index==arr.length-1?'':','
        });
        sql_str = `select ${column_str} from ${table_name}`
    }
      return new Promise(function (resolve, reject) {
        getConnect().then(function (conn) {
            conn.query(sql_str, function (err, result) {
                if (err) {
                    reject(err)
                } else {
                    resolve(result)
                }
                conn.destroy();
            })

        }).catch(e => console.log(e))
    })

}


module.exports = {selectTable}
